#ifndef RTSP_SERVICE_RTP_USER_H
#define RTSP_SERVICE_RTP_USER_H

#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "TWList.h"
#include "rtp_unit.h"


#define RTPUSER_RET_ERR             -1
#define RTPUSER_RET_SUCCEED         0
#define RTPUSER_RET_WAIT            1

#define RTPUSER_SOCKET_SUCCEED       0
#define RTPUSER_SOCKET_CREATE_ERR   -1      //套接字创建错误
#define RTPUSER_SOCKET_SET_ERR      -2      //套接字设置错误
#define RTPUSER_SOCKET_BIND_ERR     -3      //套接字绑定错误

#define RTPUSER_TYPE_NONE   0
#define RTPUSER_TYPE_UDP    1
#define RTPUSER_TYPE_TCP    2

#define RTPUSER_STATE_PALY      0       //播放
#define RTPUSER_STATE_PAUSE     1       //暂停
#define RTPUSER_STATE_CANCEL    2       //取消

typedef struct RTPUser {
    unsigned char state;               //用户状态
    struct TWListNode *rtpunit_node;   //RTP资源节点

    unsigned char type;                //类型TCP or UDP
    int send_socket;                   //UDP发送套接字, TCP连接时保存TCP套接字
    struct sockaddr_in s_rtp_in;       //本机RTP套接字信息
    struct sockaddr_in c_rtp_in;       //客户RTP套接字信息,TCP连接时保存TCP的信息
    int recv_socket;                   //UDP接收套接字
    struct sockaddr_in s_rtcp_in;      //本机RTCP套接字信息
    struct sockaddr_in c_rtcp_in;      //客户RTCP套接字信息,TCP连接时保存TCP的信息
} RTPUser;

//绑定服务UDP端口
extern int RTPUser_udp_init(RTPUser *user,
                            char *s_ip,
                            unsigned short ssend_port,
                            unsigned short srecv_port);
//释放UDP端口
int RTPUser_udp_free(RTPUser *user);

//初始化TCP服务配置
extern int RTPUser_tcp_init(RTPUser *user, TWListNode *rtp_unit, int c_socket, struct sockaddr_in *c_in);

extern void RTPUser_state_set(RTPUser *user, unsigned char state);

#endif //RTSP_SERVICE_RTP_USER_H
